import { defineEventHandler, getQuery } from 'h3';

// 模拟业态模板数据
const mockTemplates = [
  {
    id: 'hotel-basic',
    name: '酒店基础版',
    industryType: 'hotel',
    version: '1.0.0',
    description: '适合小型酒店的SaaS解决方案',
    features: ['房间管理', '预订系统', '客户管理', '基础报表'],
    resources: [
      {
        id: '1',
        name: '酒店管理系统',
        type: 'service',
        required: true,
      },
    ],
    pricing: {
      setupFee: 0,
      monthlyFee: 599,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '30分钟',
      requirements: {
        cpu: '2核',
        memory: '4GB',
        storage: '50GB',
      },
    },
    status: 'active',
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-15T10:30:00Z',
    createdBy: 'admin',
  },
  {
    id: 'hotel-premium',
    name: '酒店高级版',
    industryType: 'hotel',
    version: '1.0.0',
    description: '适合中大型酒店的完整SaaS解决方案',
    features: [
      '房间管理',
      '预订系统',
      '客户管理',
      '财务管理',
      '员工管理',
      '高级报表',
      '多语言支持',
      'API集成',
    ],
    resources: [
      {
        id: '1',
        name: '酒店管理系统',
        type: 'service',
        required: true,
      },
      {
        id: 'payment-gateway',
        name: '支付网关',
        type: 'service',
        required: false,
      },
      {
        id: 'notification-service',
        name: '通知服务',
        type: 'service',
        required: false,
      },
    ],
    pricing: {
      setupFee: 999,
      monthlyFee: 1999,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '60分钟',
      requirements: {
        cpu: '4核',
        memory: '8GB',
        storage: '100GB',
      },
    },
    status: 'active',
    createdAt: '2024-01-01T00:00:00Z',
    updatedAt: '2024-01-15T10:30:00Z',
    createdBy: 'admin',
  },
  {
    id: 'pet-basic',
    name: '宠物基础版',
    industryType: 'pet',
    version: '0.9.0',
    description: '适合小型宠物店的SaaS解决方案',
    features: ['宠物档案', '服务预约', '基础商品管理', '客户管理'],
    resources: [
      {
        id: '2',
        name: '宠物店管理系统',
        type: 'service',
        required: true,
      },
    ],
    pricing: {
      setupFee: 0,
      monthlyFee: 399,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '20分钟',
      requirements: {
        cpu: '1核',
        memory: '2GB',
        storage: '20GB',
      },
    },
    status: 'active',
    createdAt: '2024-01-12T14:30:00Z',
    updatedAt: '2024-01-15T16:20:00Z',
    createdBy: 'admin',
  },
  {
    id: 'education-basic',
    name: '教育基础版',
    industryType: 'education',
    version: '2.1.0',
    description: '适合小型教育机构的SaaS解决方案',
    features: ['学生管理', '课程管理', '成绩管理', '基础报表'],
    resources: [
      {
        id: '3',
        name: '教育管理系统',
        type: 'service',
        required: true,
      },
    ],
    pricing: {
      setupFee: 0,
      monthlyFee: 1299,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '45分钟',
      requirements: {
        cpu: '2核',
        memory: '4GB',
        storage: '50GB',
      },
    },
    status: 'active',
    createdAt: '2023-12-01T00:00:00Z',
    updatedAt: '2024-01-10T11:15:00Z',
    createdBy: 'admin',
  },
  {
    id: 'education-premium',
    name: '教育高级版',
    industryType: 'education',
    version: '2.1.0',
    description: '适合大型教育机构的完整SaaS解决方案',
    features: [
      '学生管理',
      '课程管理',
      '成绩管理',
      '教师管理',
      '在线学习',
      '考试系统',
      '财务系统',
      '高级报表',
      '多校区管理',
    ],
    resources: [
      {
        id: '3',
        name: '教育管理系统',
        type: 'service',
        required: true,
      },
      {
        id: 'notification-service',
        name: '通知服务',
        type: 'service',
        required: false,
      },
      {
        id: 'video-service',
        name: '视频服务',
        type: 'service',
        required: false,
      },
    ],
    pricing: {
      setupFee: 1999,
      monthlyFee: 3999,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '90分钟',
      requirements: {
        cpu: '8核',
        memory: '16GB',
        storage: '200GB',
      },
    },
    status: 'active',
    createdAt: '2023-12-01T00:00:00Z',
    updatedAt: '2024-01-10T11:15:00Z',
    createdBy: 'admin',
  },
  {
    id: 'retail-standard',
    name: '零售标准版',
    industryType: 'retail',
    version: '1.5.0',
    description: '适合中小型零售店铺的SaaS解决方案',
    features: ['商品管理', '销售记录', '库存管理', '会员管理', '基础报表'],
    resources: [
      {
        id: '4',
        name: '零售POS系统',
        type: 'service',
        required: true,
      },
    ],
    pricing: {
      setupFee: 299,
      monthlyFee: 799,
      currency: 'CNY',
    },
    deployment: {
      estimatedTime: '30分钟',
      requirements: {
        cpu: '2核',
        memory: '4GB',
        storage: '50GB',
      },
    },
    status: 'active',
    createdAt: '2023-11-01T00:00:00Z',
    updatedAt: '2024-01-08T14:45:00Z',
    createdBy: 'admin',
  },
];

export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { page = 1, pageSize = 10, industryType, status } = query;

  // 过滤数据
  let filteredData = [...mockTemplates];

  if (industryType) {
    filteredData = filteredData.filter(
      (template) => template.industryType === industryType,
    );
  }

  if (status) {
    filteredData = filteredData.filter(
      (template) => template.status === status,
    );
  }

  // 分页
  const pageNum = parseInt(page.toString());
  const size = parseInt(pageSize.toString());
  const start = (pageNum - 1) * size;
  const end = start + size;
  const paginatedData = filteredData.slice(start, end);

  return {
    success: true,
    data: {
      list: paginatedData,
      pagination: {
        current: pageNum,
        pageSize: size,
        total: filteredData.length,
        totalPages: Math.ceil(filteredData.length / size),
      },
    },
    message: '查询成功',
  };
});
